<?php

namespace App\Module\Api\Controllers;
use App\Module\Api\Controllers\Request\OrderListWhereRequest;
use App\Module\Api\Validator\OrderListValidator;
use App\System\Activity\Repositories\ActiveInfoRepository;
use App\System\Base\Services\UserTokenService;
use App\System\Goods\Repositories\GoodsInfoRepository;
use App\System\Oms\Repositories\OrderInfoRepository;
use App\System\Order\Repositories\OrderGivingRepository;
use App\System\Order\Repositories\OrderGoodsRepository;


/**
 * 订单列表
 */
class OrderListController extends Controller
{
    public function __construct()
    {
        $this->where = new OrderListWhereRequest();
        parent::__construct();


    }

    public function index()
    {

//        $user_id = UserTokenService::getUserId();
        $user_id = checkSession();
        (new OrderListValidator())->check();
        $action = $this->query->action;
        $order = OrderGoodsRepository::getInstance();
        if ($action ==1){
            //课程订单
            $data = $order->getApiList($this->table,$this->where,$user_id);

        }elseif($action==2){
            //活动订单
            $active = ActiveInfoRepository::getInstance();
            $data = $active->getApiList($this->table,$this->where,$user_id);
        }else{
            //赠送订单
            $data = $order->getGiving($this->table,$this->where,$user_id);

        }
        return apiResponse($data);


    }

    public function setOrderBy()
    {
       return [1=>'updated_at',2=>'id'];
    }
}
